package org.lyu.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * 使用C3P0数据库连接池
 * @author Administrator
 *
 */
public class MyDbUtils2 {
	
	private static ComboPooledDataSource cpds = new ComboPooledDataSource();

	/**
	 * 获取数据库连接Connection
	 * @return Connection
	 * @throws SQLException
	 */
	public static Connection getConnection() throws SQLException {
		return cpds.getConnection();
	}
	
	/**
	 * 释放资源
	 * @param rSet
	 * @param statement
	 * @param conn
	 */
	public static void close(Statement statement, Connection conn) {
		
		try {
			if (statement != null) {
				statement.close();
			}
		} catch (Exception e) {
		}
		
		try {
			if (conn != null) {
				conn.close();
			}
		} catch (Exception e) {
		}
	}
	
	/**
	 * 释放资源
	 * @param rSet
	 * @param statement
	 * @param conn
	 */
	public static void close(ResultSet rSet, Statement statement, Connection conn) {
		//释放资源
		try {
			if (rSet != null) {
				rSet.close();
			}
		} catch (Exception e) {
		}
		
		try {
			if (statement != null) {
				statement.close();
			}
		} catch (Exception e) {
		}
		
		try {
			if (conn != null) {
				conn.close();
			}
		} catch (Exception e) {
		}
	}

}
